//
//  YLChangeBankCardController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/4.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLChangeBankCardController.h"
#import "YLGlobeHeader.h"
#import "YLMyInfoModel.h"
#import "YLChangeBankCardViewModel.h"
#import "WHProgressHUD.h"
#import "YLMineViewModel.h"
@interface YLChangeBankCardController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UITextField *bankCardTextField;

@property (weak, nonatomic) IBOutlet UIButton *sureButton;
@property (weak, nonatomic) IBOutlet UITextField *bankNameOriginalLabel;
@property (weak, nonatomic) IBOutlet UITextField *bankCodeOriginalLabel;
@property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField;
@property (nonatomic, assign) BOOL aa;

@property (nonatomic, strong) YLMineViewModel *myInfoViewModel;
@end

@interface YLChangeBankCardController()

@property (nonatomic, strong) YLChangeBankCardViewModel *viewModel;
@end

@implementation YLChangeBankCardController

- (YLChangeBankCardViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLChangeBankCardViewModel alloc] init];
        _viewModel.bankCodeOriginal = _model.authBankCode;
    }
    return _viewModel;
}

- (YLMineViewModel *)myInfoViewModel
{
    if (!_myInfoViewModel) {
        _myInfoViewModel = [[YLMineViewModel alloc] init];
    }
    return _myInfoViewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrollView.alwaysBounceVertical = YES;
    self.title = @"更换银行卡";
    
    
    _bankCodeOriginalLabel.text = _model.authBankCode;
    _bankNameOriginalLabel.text = _model.authBankName;
   
    RAC(self.viewModel, bankCodeNow) = _bankCardTextField.rac_textSignal;
    RAC(self.viewModel, phoneNumber) = _phoneNumberTextField.rac_textSignal;
    RAC(_sureButton, enabled) = self.viewModel.sureEnableSignal;
}

- (void)loadData
{
    __weak typeof(self) weakSelf = self;
    [[self.myInfoViewModel.myInfoCommand execute:nil] subscribeNext:^(id  _Nullable x) {
       [WHProgressHUD showSuccess:@"银行卡更换成功"];
       weakSelf.model.authBankName =  weakSelf.myInfoViewModel.myInfoModel.authBankName;
        weakSelf.model.authBankCode = weakSelf.myInfoViewModel.myInfoModel.authBankCode;
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)changeCard:(UIButton *)sender {
    __weak typeof(self) weakSelf = self;
    [[self.viewModel.requestCommand execute:nil] subscribeNext:^(id  _Nullable x) {
        [weakSelf loadData];
    }];
}

@end
